from db import db


class Student(db.Model):
    __tablename__ = "student"
    xh = db.Column(db.String(11), primary_key=True)
    name = db.Column(db.String(30))
    sex = db.Column(db.String(10))
    nationality = db.Column(db.String(10))
    year = db.Column(db.String(4))
    id_card = db.Column(db.String(30))
    school = db.Column(db.String(50))
    major = db.Column(db.String(20))
    class_name = db.Column(db.String(50))
    home_address = db.Column(db.String(255))
    bank_name = db.Column(db.String(100))
    bank_number = db.Column(db.String(30))
    phone = db.Column(db.String(20))
    email = db.Column(db.String(20))
    qs = db.Column(db.String(100))
    ksh = db.Column(db.String(20))

    def __init__(self, obj):
        self.xh = obj['xh']
        self.name = obj['name'],
        self.sex = obj['sex'],
        self.nationality = obj['nationality']
        self.year = obj['year']
        self.id_card = obj['idCard']
        self.school = obj['school']
        self.major = obj['major']
        self.class_name = obj['className']
        self.home_address = obj['homeAddress']
        self.bank_name = obj['bankName']
        self.bank_number = obj['bankNumber']
        self.phone = obj['phone']
        self.email = obj['email']
        self.qs = obj['qs']
        self.ksh = obj['ksh']

    def __repr__(self):
        return str(self.name)

    def to_json(self):
        dict = self.__dict__
        if "_sa_instance_state" in dict:
            del dict["_sa_instance_state"]
        return dict


if __name__ == '__main__':
    db.create_all()
